$(document).ready(function(){
	// init
	$('#currentPassword').val('');
	$('#newPassword').val('');
	$('#newPasswordConfirm').val('');
	
	// init change password dialog
	$('#changePasswordDialog').dialog({
		autoOpen: false,
		width: 330,
		modal: true,
		resizable: false,
		buttons:{			
			"Đổi mật khẩu": function(){
				changePassword();
			},
			"Thoát": function(){
				$(this).dialog("close");
			}
		}
	});
	
	$('#profileLink').click(function(){
		$('#changePasswordDialog').dialog("open");
	});
	
	function changePassword()
	{
		$.post("/profile/change-password", $('#changePasswordForm').serialize(), function(data){
			var jsonData = $.parseJSON(data);			
			if (jsonData.code == 0)
			{
				window.location.href = window.location.pathname;
			}
			else
			{
				$("#errorMessage").css("display", "");
				$("#errorMessage td").html(jsonData.data);
			}
		});
	}
});